%macro get_w2g;

	
	proc printto new log = "&logdir./get_w2g.txt";
	run;
	

	/****************************************************
	*			Put individuals into a tinlist			*
	****************************************************/
	%make_tinlist;


	
		/****************************************
		*										*
		*			Start PROC SQL				*
		*										*
		****************************************/

			
				proc sql noprint;
				[connection details redacted]
					create table rlib.w2g as
					select * from connection to iq 
					(
					select 
						a.[redacted] as person_id,
						sum(a.[redacted]) as gambling_incm,
						sum(a.[redacted]) as w2g_wh
					from [redacted] as a
						inner join #tinlist as b
							on(a.[redacted] = b.person_id)
					where a.[redacted] = &base_yr
						and a.[redacted] <= 4
					group by a.tin
					order by a.tin
					);
				disconnect from iq;
				quit;



	

	proc printto;
	run;

	


%mend;
